var FOV = {
	getFov: function(/*vec2*/ origin, /*MapManager*/ map, /*int*/ size){
		map.setDark();
		map.map[origin.b][origin.a].v = 2;
		
		var dist = size;
		size = 10;
		for (var i=0,len=size*2;i<len;i++){
			this.castRay(origin.clone(), origin.a - size + i, origin.b - size, map, dist);
			this.castRay(origin.clone(), origin.a - size + i, origin.b + size, map, dist);
			
			this.castRay(origin.clone(), origin.a - size, origin.b - size + i, map, dist);
			this.castRay(origin.clone(), origin.a + size, origin.b - size + i, map, dist);
		}
	},
	
	castRay: function(origin, x, y, map, dist){
		var xx = x - origin.a;
		var yy = origin.b - y;
		
		var ang = Math.atan2(yy, xx);
		
		xx = Math.cos(ang);
		yy = -Math.sin(ang);
		
		var vec = vec2(xx, yy);
		
		while (dist > 0){
			yy = Math.round(origin.b);
			xx = Math.round(origin.a);
			
			if (!map.map[yy]) break;
			if (!map.map[yy][xx]) break;
			
			dist--;
			map.map[yy][xx].v = 2;
			if (map.isSolid(xx,yy))
				dist = 0;
				
			origin.sum(vec);
		}
	}
};
